import { getAppNav } from '@/App'
import { tabBarKeyList } from '@/layout/CTabBar/CTabBar'
import { Button, ErrorBlock } from 'antd-mobile'

export default function Exception404() {
  return (
    <div>
      <ErrorBlock fullPage></ErrorBlock>
      {tabBarKeyList.includes(window.location.pathname) ? null : (
        <div className="flex-center m-t-10">
          <Button
            color="primary"
            onClick={() => {
              backClick()
            }}
          >
            返回
          </Button>
        </div>
      )}
    </div>
  )
}

// 点击返回按钮
function backClick() {
  if (window.history.length === 1 || window.history.length === 2) {
    getAppNav()('/') // 防止直接打开 /404，然后返回时没有可以返回的 路由，所以就直接返回 /
  } else {
    getAppNav()(-1)
  }
}
